import 'package:architecture/os_size.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:study_demo/ui/tool/phone_num_query/phone_num_query_controller.dart';

import '../../../widgets/text_button.dart';

class PhoneNumQueryPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetX<PhoneNumQueryController>(
        init: PhoneNumQueryController(),
        builder: (controller) {
          return Scaffold(
            appBar: AppBar(title: Text('手机号码归属地查询')),
            body: Row(
              children: [
                Container(
                    width: windowWidth * 0.15,
                    margin: EdgeInsets.symmetric(horizontal: 15),
                    child: TextField(
                        controller: controller.phoneNumEditingController,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                            hintText: '请输入手机号码',
                            suffixIcon: IconButton(
                                onPressed: () {
                                  controller.clear();
                                },
                                icon: Icon(
                                  Icons.clear,
                                  size: 20,
                                ))))),
                _textButton('查询', width: 60, onPressed: () {
                  controller.query();
                }),
                SizedBox(
                  width: 15,
                ),
                Container(
                    margin: EdgeInsets.only(top: 10),
                    child: Text(
                      controller.result.value,
                      style: TextStyle(color: Colors.deepPurpleAccent),
                    )),
                SizedBox(
                  width: 15,
                ),
                _textButton('复制', width: 60, onPressed: () {
                  controller.copy();
                }),
              ],
            ),
          );
        });
  }

  _textButton(String text, {double width = 90, Function? onPressed}) {
    return Container(
        width: width,
        height: 25,
        margin: EdgeInsets.only(top: 15),
        child: MyTextButton(
            text: text,
            confirm: () {
              onPressed?.call();
            },
            backgroundColor: Colors.deepPurpleAccent,
            textStyle: TextStyle(color: Colors.white)));
  }
}
